

--filename=文件名
local cjson = require "cjson"
local filename = ngx.var.arg_filename

local tb_err = {}
if not filename then
  tb_err.code =999
  tb_err.content = "no"
  return ngx.say(cjson.encode(tb_err))
end

local file = io.open("/image_root/" .. filename,"r")
if not file then
  local file2 = io.open("/data/logs/" .. filename,"r")
  if not file2 then
    tb_err.code =999
    tb_err.content = "no file"
    return ngx.say(cjson.encode(tb_err))
  end
  local str_file = file2:read("*all")
  ngx.header["Content-Disposition"] = "attachment;filename=" .. filename
  ngx.say(str_file)
  return 
end

local str_file = file:read("*all")
ngx.header["Content-Disposition"] = "attachment;filename=" .. filename
ngx.say(str_file)